package #1;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class ResultBean<T> {
	// 请求成功
	@JsonIgnore
	public final static String OK = "200";
	// 系统异常
	@JsonIgnore
	public final static String EXCEPTION = "500"; 
	// 未找到资源
	@JsonIgnore
	public final static String NOT_FOUND = "404"; 
	// 请求失败
	@JsonIgnore
	public final static String FAIL = "400"; 


	private String code = OK;
	
	private String msg = "";
	
	private T entity;

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setCodeAndMsg(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public ResultBean() {
		super();
	}

	public ResultBean(String code, String msg, T entity) {
		super();
		this.code = code;
		this.msg = msg;
		this.entity = entity;
	}

	public ResultBean(String msg, T entity) {
		super();
		this.msg = msg;
		this.entity = entity;
	}

	public ResultBean(String code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}

	public ResultBean(String msg) {
		super();
		this.msg = msg;
	}

	public ResultBean(T entity) {
		super();
		this.entity = entity;
	}

	public ResultBean(T entity, String code) {
		super();
		this.entity = entity;
		this.code = code;
	}

	public static <T> ResultBean<T> createSuccess(String msg) {
		return new ResultBean<T>(msg);
	}

	public static <T> ResultBean<T> createSuccess(String msg, T data) {
		return new ResultBean<T>(msg, data);
	}

	public static <T> ResultBean<T> createSuccess(T data) {
		return new ResultBean<T>(data);
	}

	public static <T> ResultBean<T> createSuccess() {
		return new ResultBean<T>();
	}

	public static <T> ResultBean<T> createFail() {
		return new ResultBean<T>(FAIL);
	}

	public static <T> ResultBean<T> createFail(String msg) {
		return new ResultBean<T>(FAIL, msg);
	}

	public static <T> ResultBean<T> createFail(String msg, T data) {
		return new ResultBean<T>(FAIL, msg, data);
	}

}
